package cn.pconline.autoclub.service.bbssync;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;

import cn.pconline.autoclub.entity.Club;
import cn.pconline.autoclub.entity.ClubMember;
import cn.pconline.autoclub.entity.User;
import cn.pconline.autoclub.service.DynaService;
import cn.pconline.autoclub.service.PetrolService;

import com.alibaba.fastjson.JSONObject;

/**
 * @author zhouruxuan
 * @date 2014年12月4日 上午11:08:09
 */
public class SyncUpdateReplyService extends BbsSyncPetrolService {
    @Autowired
    private DynaService dynaService;
    @Autowired
    private PetrolService petrolService;
    
    @Override
    protected int addPetroltoMember(ClubMember clubMember, JSONObject msg) {
        log.info("update topic reply not need add petrol to member");
        return 0;
    }

    @Override
    protected int addPetroltoClub(Club club, JSONObject msg) {
        log.info("update topic reply not need add petrol to club");
        return 0;
    }

    @Override
    protected long getUserId(JSONObject msg) {
        return msg.getLongValue("postAuthorId");
    }
    
    @Override
    public void process(JSONObject msg, ClubMember clubMember) {
        
        // 验证用户
        long userId = getUserId(msg);
        if (userId <= 0L) {
            log.info("not userId-{}", userId);
            return;
        }

        //判断用户是否登录
        User user = userService.authUser(userId);
        if (user == null || user.getUid() == 0L) {
            log.info("not found user-{}", userId);
            return;
        }

        // 更新回帖
        long topicId = msg.getLongValue("topicId");
        Date createAt = msg.getDate("topicCreateAt");
        long postId = msg.getLongValue("postId");
        String content = msg.getString("postMessage");
        dynaService.updateDynaReply(topicId, createAt, postId, content);
    }
}
